package com.example.helloworld;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.i("MainActivity", "onCreate execute");
        Button btnClick = findViewById(R.id.btn_click);//控件的获取
        btnClick.setOnClickListener(MainActivity.this);        
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_click:
                long t1 = System.currentTimeMillis();
                System.out.println(t1);
        
                int count = 1 ;                                  
                while (true)   {
                    if (count > 1000000000) {
                        break;
                    }
                    count += 1 ;
                } 
                long t2 = System.currentTimeMillis();
                //里面写点击后想要实现的效果
                Toast.makeText(MainActivity.this,
                        "按钮被点击"+(t2-t1), Toast.LENGTH_SHORT).show();
                //这里是弹出一个消息---"按钮被点击"
        }
    }
}